<template>
  <div class="flex flex-col h-full">
    <div class="w-full flex justify-center">
      <a-radio-group v-model:value="activeTab" button-style="solid" class="w-full" @change="onChangeTab">
        <a-radio-button value="2" class="w-1/3 text-center">全部</a-radio-button>
        <a-radio-button value="0" class="w-1/3 text-center">处置</a-radio-button>
        <a-radio-button value="1" class="w-1/3 text-center">西成药</a-radio-button>
      </a-radio-group>
    </div>
    <div class="flex-1 overflow-y-scroll mt-2">
      <div v-for="(item, index) in tableData" :key="index" class="w-full flex items-center cell-style" @dblclick="onDbClick(item)">
        <div v-if="item?.mc" class="truncate mr-2" :title="item?.mc">{{ item?.mc }}</div>
        <div v-if="item?.gg" class="text-gray-400 mr-1 text-xs truncate" :title="item?.gg">{{ item?.gg }}</div>
        <div v-if="item?.cj" class="text-gray-400 text-xs max-w-[64px] truncate" :title="item?.cj">{{ item.cj }}</div>
      </div>
    </div>
    <a-button type="primary" ghost class="mt-2 mb-1" @click="getData(true)">
      <template #icon> <SyncOutlined /> </template>
      刷新
    </a-button>
  </div>
</template>
<script setup>
import { onMounted } from 'vue'
import { SyncOutlined } from '@ant-design/icons-vue'
import { message } from 'ant-design-vue'
import useUserStore from '@/store/user'
import useStore from '@/views/out-doctor/store'

const props = defineProps({
  activeKey: {
    type: String,
    default: ''
  }
})
const store = useStore()
const { empId } = useUserStore()
const activeTab = ref('2')
const tableData = ref([])
const onChangeTab = () => {
  getData()
}
const getData = async (flag) => {
  const res = await post('/outp/mzys/getDoctorCommonClinicalOrderList', {
    ysbh: empId,
    czcf: activeTab.value
  })
  if (res.code !== 0) return message.error(res.msg || '请求失败')
  if (flag) message.success('刷新成功')
  tableData.value = res.data || []
}
const onDbClick = async (item) => {
  // const res = await post('/outp/mzys/doubleClickSaveClinicalOrder', {
  //   copyTypeString: item.copyTypeString,
  //   bh: item.bh,
  //   jzbh: store.currentPatient.jzbh
  // })
  // if (res.code !== 0) return message.error(res.msg || '请求失败')
  // message.success(res.msg || '保存成功')
  store.clickInfo = item
  store.isFresh = true
}

onMounted(() => {
  getData()
})
watch(
  () => props.activeKey,
  (val) => {
    if (val === '3') {
      activeTab.value = '0'
      getData()
    } else if (val === '4') {
      activeTab.value = '1'
      getData()
    } else if (val === '2') {
      activeTab.value = '2'
      getData()
    }
  }
)
</script>
<style lang="less" scoped>
.cell-style {
  margin-bottom: 4px;
  padding: 4px 11px;
  padding-top: 6px;
  border: 1px solid #ccc;
  border-radius: 4px;
  cursor: pointer;
  &:hover {
    border: 1px solid var(--primary-color);
  }
}
</style>
